<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>添加用户</title>
		<link href="css/gl/tjyh.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src='dwr/engine.js'>
</script>
		<script type="text/javascript" src='dwr/util.js'>
</script>
		<script type="text/javascript" src="script/jquery/jquery-1.5.1.min.js">
</script>
		<script type="text/javascript" src='dwr/interface/UserDwr.js'>
</script>
<script type="text/javascript">
//添加通告
function AddAward(){
	var uname = $("#uname").val();
	var pwd = $("#pwd").val();
	var repwd = $("#repwd").val();
	var pmt = $("#pmt").val();
	var right = $("#right").val();
	if(uname.length<1){
		alert("用户名称不能为空！");
		return false;
	}else if(uname.length>20){
		alert("用户名称字数应小于20！");
		return false;
	}
	if(pwd.length<1){
		alert("密码不能为空！");
		return false;
	}
	if(repwd.length<1){
		alert("确认密码不能为空！");
		return false;
	}
	if(pmt.length<1){
		alert("请选择部门！");
		return false;
	}
	if(right.length<1){
		alert("请选择角色！");
		return false;
	}
	if(pwd!=repwd){
		alert("两次输入密码不一样！");
		return false;
	}
	UserDwr.AddUser(0,uname,pwd,Number(pmt),Number(right),function(data){
		if(data==0){
			alert("添加失败！");
		}else if(data>0){
			alert("添加成功！");
			$("#uname").val("");
	        $("#pwd").val("");
	        $("#repwd").val("");
	        $("#repwd").val("");
	        $("#right").val("0");
		}else{
			alert("已存在同名用户！");
		}
	});
}
$(function() {
	UserDwr.GetDepartment(function(data){
		$("#pmt").find("option").remove();
		for(var i=0;i<data.length;i++){
	       $("#pmt").append("<option value='"+data[i].id+"'>"+data[i].name+"</option>"); 
		}
	});
});
</script>
	</head>

	<body>
			<div id="page_all">
				<jsp:include page="title.jsp" flush="true">
					<jsp:param name="jspName" value="yhModuleOpt" />
				</jsp:include>
				<div id="main">
					<div id="tgleft">
						<jsp:include page="yhleft.jsp" flush="true">
							<jsp:param name="jspName" value="tjyh" />
						</jsp:include>
					</div>
					<div id="tgmain">
						<table id="addnotice" cellpadding="0" cellspacing="0">
							<tr>
								<td class="ftd">
									用户名:
								</td>
								<td>
									<input id="uname" style="width:155px;" maxlength="20">
								</td>
							</tr>
							<tr>
								<td class="ftd" style="vertical-align: top;">
									密码:
								</td>
								<td style="padding-top:5px; ">
									<input id="pwd" type="password" style="width:155px;" maxlength="20">
								</td>
							</tr>
							<tr>
								<td class="ftd" style="vertical-align: top;">
									确认密码:
								</td>
								<td style="padding-top:5px; ">
									<input id="repwd" type="password" style="width:155px;" maxlength="20">
								</td>
							</tr>
							<tr>
								<td class="ftd">
									部门:
								</td>
								<td>
									<select id="pmt">
									</select>
								</td>
							</tr>
							<tr>
								<td class="ftd">
									角色:
								</td>
								<td>
									<select id="right">
										<option value="0">
											管理员
										</option>
										<option value="1">
											信息员
										</option>
									</select>
								</td>
							</tr>
						</table>
						<div class="bunpanel" style="">
							<img alt="" style="cursor: pointer;" src="img/gl/addbtn.jpg"
								onclick="AddAward()" />
						</div>
					</div>
				</div>
				<div id="footer">
					<jsp:include page="footer.jsp" flush="true"></jsp:include>
				</div>
			</div>
	</body>
</html>
